#ifndef __OPE_H__
#define __OPE_H__

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>         
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <pthread.h>
#include <sqlite3.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


#define ERRLOG(errmsg) do{\
                            perror(errmsg);\
                            printf("%s-%s-%d\n", __FILE__, __func__, __LINE__);\
                            exit(1);\
                            }while(0)

typedef struct{             //员工结构体
    int job;                //工号
    char name[20];          //名字
    char pwd[20];           //密码
    unsigned char type;     //类型 管理员1 普通用户0
    int level;              //员工等级(1~5)
    int age;                //年龄
    char addr[50];          //住址
    char phone[12];         //电话
    double salary;          //工资
    char des[128];          //保存错误信息  历史信息
}USER;

enum OPE{                   //操作码
    LOGIN=0,                //登录
    INC,                    //增加
    DEL,                    //删除
    REM_NAME,               //修改
    REM_PWD,
    REM_TYPE,
    REM_LEVEL,
    REM_AGE,
    REM_ADDR,
    REM_PHONE,
    REM_SASLARY,
    FIND,                   //查找个人
    FINDALL,                //查找全部
    HISTORY                 //历史
};

typedef union{				//员工联合体
	int no;					//员工号，唯一标识
	char name[20];			//名字
	char pwd[20];			//密码
	unsigned char type;		//用户类型  管理员为1，普通用户为0
	int level;				//员工等级
	int age;				//年龄
	char addr[50];			//员工住址
	char phone[12];			//电话
	double salary;			//工资
}USER_UNION;

typedef struct{             //消息结构体
    enum OPE ope;
    USER Usemsg;
}MSG;

typedef struct{             //线程传参
    int accept_fd;
    struct sockaddr_in clientaddr;
    sqlite3 *db;
    int fd;
    time_t t;
    struct  tm *lt;
    
}THREAD_PASS;

//客户端函数
//员工操作
void staff_open(int sockfd,MSG *msg,USER *user);
//员工查询
void staff_search(USER *user);
//员工修改
void staff_rem();

//管理员操作
void admin_open(int sockfd,MSG *msg,USER *user);
//添加
void admin_add(int sockfd,MSG *msg,USER *user);
//删除
void admin_del(int sockfd,MSG *msg,USER *user);
//修改
void admin_rem(int sockfd,MSG *msg,USER *user);
//查询
void admin_search(int sockfd,MSG *msg,USER *user);
//历史
void admin_history(int sockfd,MSG *msg,USER *user);


//服务器函数
void login_fun(void *arg,MSG *msg);
void inc_fun(void *arg,MSG *msg);
void del_fun(void *arg,MSG *msg);
void rem_pwd_fun(void *arg,MSG *msg);
void rem_addr_fun(void *arg,MSG *msg);
void rem_phone_fun(void *arg,MSG *msg);
void rem_name_fun(void *arg,MSG *msg);
void rem_saslary_fun(void *arg,MSG *msg);
void rem_age_fun(void *arg,MSG *msg);
void rem_level_fun(void *arg,MSG *msg);
void rem_find_fun(void *arg,MSG *msg);
void rem_findall_fun(void *arg,MSG *msg);
void rem_history_fun(void *arg,MSG *msg);

#endif